'use strict';

const Service = require('egg').Service;

class LibraryService extends Service {

    async get() {
        const { Library } = this.ctx.model;
        let library = await Library.findOne({
            where: {
                id: 1
            }
        });

        if (!library) {
            this.ctx.throw(404, '配置不存在！')
        }

        return library;
    }

    async update(request) {
        const { Library } = this.ctx.model;
        let library = await Library.findOne({
            where: {
                id: 1
            }
        });

        if (!library) {
            this.ctx.throw(404, '配置不存在！')
        }

        const { beginTime, endTime, perDayPay } = request;
        library.beginTime = beginTime;
        library.endTime = endTime;
        library.perDayPay = perDayPay;
        library.updateDate = new Date();
        library.updateBy = this.ctx.state.user.id;

        await library.save();
        return {
            result: true
        }
    }
}
module.exports = LibraryService;
